<!DOCTYPE html>
<html lang="en">
<head>
    
    <meta charset="utf-8">
    <title>client/api/bits.js - JIFF Library Documentation</title>
    
    
    
    
    
    <script src="scripts/prettify/prettify.js"></script>
    <script src="scripts/prettify/lang-css.js"></script>
    <!--[if lt IE 9]>
      <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
    <![endif]-->
    <link type="text/css" rel="stylesheet" href="styles/prettify.css">
    <link type="text/css" rel="stylesheet" href="styles/jsdoc.css">
    <script src="scripts/nav.js" defer></script>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>

<input type="checkbox" id="nav-trigger" class="nav-trigger" />
<label for="nav-trigger" class="navicon-button x">
  <div class="navicon"></div>
</label>

<label for="nav-trigger" class="overlay"></label>

<nav >
    
    <input type="text" id="nav-search" placeholder="Search" />
    
    <h2><a href="index.html">Home</a></h2><h2><a href="https://github.com/multiparty/jiff" target="_blank" class="menu-item" id="github_link" >Github Repo</a></h2><h2><a href="./intro.html" target="_self" class="menu-item" id="github_link" >Tutorial</a></h2><h2><a href="./contributing.html" target="_self" class="menu-item" id="github_link" >Contributing to JIFF</a></h2><h3>Classes</h3><ul><li><a href="GuardedSocket.html">GuardedSocket</a><ul class='methods'><li data-type='method'><a href="GuardedSocket.html#disconnect">disconnect</a></li><li data-type='method'><a href="GuardedSocket.html#is_empty">is_empty</a></li><li data-type='method'><a href="GuardedSocket.html#resend_mailbox">resend_mailbox</a></li><li data-type='method'><a href="GuardedSocket.html#safe_disconnect">safe_disconnect</a></li><li data-type='method'><a href="GuardedSocket.html#safe_emit">safe_emit</a></li></ul></li><li><a href="helpers.Deferred.html">Deferred</a><ul class='methods'><li data-type='method'><a href="helpers.Deferred.html#reject">reject</a></li><li data-type='method'><a href="helpers.Deferred.html#resolve">resolve</a></li></ul></li><li><a href="module-jiff-client-JIFFClient.html">JIFFClient</a><ul class='methods'><li data-type='method'><a href="module-jiff-client-JIFFClient.html#add_to_barriers">add_to_barriers</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient.html#apply_extension">apply_extension</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient.html#can_apply_extension">can_apply_extension</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient.html#connect">connect</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient.html#disconnect">disconnect</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient.html#emit">emit</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient.html#end_barrier">end_barrier</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient.html#executePreprocessing">executePreprocessing</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient.html#extension_applied">extension_applied</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient.html#free">free</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient.html#from_crypto_provider">from_crypto_provider</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient.html#gen_op_id">gen_op_id</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient.html#gen_op_id2">gen_op_id2</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient.html#gen_op_id2_preprocessing">gen_op_id2_preprocessing</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient.html#gen_op_id_preprocessing">gen_op_id_preprocessing</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient.html#get_preprocessing">get_preprocessing</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient.html#has_extension">has_extension</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient.html#has_preprocessing">has_preprocessing</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient.html#internal_open">internal_open</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient.html#internal_share">internal_share</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient.html#isInitialized">isInitialized</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient.html#isReady">isReady</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient.html#listen">listen</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient.html#open">open</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient.html#open_array">open_array</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient.html#preprocessing">preprocessing</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient.html#preprocessingDaemon">preprocessingDaemon</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient.html#receive_open">receive_open</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient.html#remove_listener">remove_listener</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient.html#reshare">reshare</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient.html#seed_ids">seed_ids</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient.html#share">share</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient.html#share_array">share_array</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient.html#start_barrier">start_barrier</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient.html#store_preprocessing">store_preprocessing</a></li></ul></li><li><a href="module-jiff-client-JIFFClient_SecretShare.html">SecretShare</a><ul class='methods'><li data-type='method'><a href="module-jiff-client-JIFFClient_SecretShare.html#add">add</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient_SecretShare.html#bit_decomposition">bit_decomposition</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient_SecretShare.html#cadd">cadd</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient_SecretShare.html#cdiv">cdiv</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient_SecretShare.html#cdivfac">cdivfac</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient_SecretShare.html#ceq">ceq</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient_SecretShare.html#cgt">cgt</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient_SecretShare.html#cgteqn">cgteqn</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient_SecretShare.html#clt">clt</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient_SecretShare.html#clteq">clteq</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient_SecretShare.html#cmult">cmult</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient_SecretShare.html#cneq">cneq</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient_SecretShare.html#cor_bit">cor_bit</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient_SecretShare.html#cpow">cpow</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient_SecretShare.html#csub">csub</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient_SecretShare.html#cxor_bit">cxor_bit</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient_SecretShare.html#div">div</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient_SecretShare.html#eq">eq</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient_SecretShare.html#error">error</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient_SecretShare.html#gt">gt</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient_SecretShare.html#gteq">gteq</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient_SecretShare.html#if_else">if_else</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient_SecretShare.html#isConstant">isConstant</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient_SecretShare.html#logLEAK">logLEAK</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient_SecretShare.html#lt">lt</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient_SecretShare.html#lt_halfprime">lt_halfprime</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient_SecretShare.html#lteq">lteq</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient_SecretShare.html#mult">mult</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient_SecretShare.html#neq">neq</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient_SecretShare.html#not">not</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient_SecretShare.html#open">open</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient_SecretShare.html#or_bit">or_bit</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient_SecretShare.html#promise_handler">promise_handler</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient_SecretShare.html#refresh">refresh</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient_SecretShare.html#sadd">sadd</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient_SecretShare.html#sdiv">sdiv</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient_SecretShare.html#seq">seq</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient_SecretShare.html#sgt">sgt</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient_SecretShare.html#sgteq">sgteq</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient_SecretShare.html#slt">slt</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient_SecretShare.html#slteq">slteq</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient_SecretShare.html#smod">smod</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient_SecretShare.html#smult">smult</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient_SecretShare.html#smult_bgw">smult_bgw</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient_SecretShare.html#sneq">sneq</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient_SecretShare.html#sor_bit">sor_bit</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient_SecretShare.html#ssub">ssub</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient_SecretShare.html#sub">sub</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient_SecretShare.html#sxor_bit">sxor_bit</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient_SecretShare.html#toString">toString</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient_SecretShare.html#valueOf">valueOf</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient_SecretShare.html#when_both_ready">when_both_ready</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient_SecretShare.html#wThen">wThen</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient_SecretShare.html#xor_bit">xor_bit</a></li></ul></li></ul><h3>Modules</h3><ul><li><a href="module-jiff-client.html">jiff-client</a></li></ul><h3>Namespaces</h3><ul><li><a href="bits.html">bits</a><ul class='methods'><li data-type='method'><a href="bits.html#.jiffClient.protocols.bits.bit_composition">jiffClient.protocols.bits.bit_composition</a></li><li data-type='method'><a href="bits.html#.jiffClient.protocols.bits.cadd">jiffClient.protocols.bits.cadd</a></li><li data-type='method'><a href="bits.html#.jiffClient.protocols.bits.cdivl">jiffClient.protocols.bits.cdivl</a></li><li data-type='method'><a href="bits.html#.jiffClient.protocols.bits.cdivr">jiffClient.protocols.bits.cdivr</a></li><li data-type='method'><a href="bits.html#.jiffClient.protocols.bits.ceq">jiffClient.protocols.bits.ceq</a></li><li data-type='method'><a href="bits.html#.jiffClient.protocols.bits.cgt">jiffClient.protocols.bits.cgt</a></li><li data-type='method'><a href="bits.html#.jiffClient.protocols.bits.cgteq">jiffClient.protocols.bits.cgteq</a></li><li data-type='method'><a href="bits.html#.jiffClient.protocols.bits.clt">jiffClient.protocols.bits.clt</a></li><li data-type='method'><a href="bits.html#.jiffClient.protocols.bits.clteq">jiffClient.protocols.bits.clteq</a></li><li data-type='method'><a href="bits.html#.jiffClient.protocols.bits.cmult">jiffClient.protocols.bits.cmult</a></li><li data-type='method'><a href="bits.html#.jiffClient.protocols.bits.cneq">jiffClient.protocols.bits.cneq</a></li><li data-type='method'><a href="bits.html#.jiffClient.protocols.bits.csubl">jiffClient.protocols.bits.csubl</a></li><li data-type='method'><a href="bits.html#.jiffClient.protocols.bits.csubr">jiffClient.protocols.bits.csubr</a></li><li data-type='method'><a href="bits.html#.jiffClient.protocols.bits.open">jiffClient.protocols.bits.open</a></li><li data-type='method'><a href="bits.html#.jiffClient.protocols.bits.rejection_sampling">jiffClient.protocols.bits.rejection_sampling</a></li><li data-type='method'><a href="bits.html#.jiffClient.protocols.bits.sadd">jiffClient.protocols.bits.sadd</a></li><li data-type='method'><a href="bits.html#.jiffClient.protocols.bits.sdiv">jiffClient.protocols.bits.sdiv</a></li><li data-type='method'><a href="bits.html#.jiffClient.protocols.bits.seq">jiffClient.protocols.bits.seq</a></li><li data-type='method'><a href="bits.html#.jiffClient.protocols.bits.sgt">jiffClient.protocols.bits.sgt</a></li><li data-type='method'><a href="bits.html#.jiffClient.protocols.bits.sgteq">jiffClient.protocols.bits.sgteq</a></li><li data-type='method'><a href="bits.html#.jiffClient.protocols.bits.share">jiffClient.protocols.bits.share</a></li><li data-type='method'><a href="bits.html#.jiffClient.protocols.bits.slt">jiffClient.protocols.bits.slt</a></li><li data-type='method'><a href="bits.html#.jiffClient.protocols.bits.slteq">jiffClient.protocols.bits.slteq</a></li><li data-type='method'><a href="bits.html#.jiffClient.protocols.bits.smult">jiffClient.protocols.bits.smult</a></li><li data-type='method'><a href="bits.html#.jiffClient.protocols.bits.sneq">jiffClient.protocols.bits.sneq</a></li><li data-type='method'><a href="bits.html#.jiffClient.protocols.bits.ssub">jiffClient.protocols.bits.ssub</a></li></ul></li><li><a href="handlers.html">handlers</a><ul class='methods'><li data-type='method'><a href="handlers.html#.jiffClient.handlers.build_initialization_message">jiffClient.handlers.build_initialization_message</a></li><li data-type='method'><a href="handlers.html#.jiffClient.handlers.connected">jiffClient.handlers.connected</a></li><li data-type='method'><a href="handlers.html#.jiffClient.handlers.error">jiffClient.handlers.error</a></li><li data-type='method'><a href="handlers.html#.jiffClient.handlers.initialized">jiffClient.handlers.initialized</a></li><li data-type='method'><a href="handlers.html#.jiffClient.handlers.receive_crypto_provider">jiffClient.handlers.receive_crypto_provider</a></li><li data-type='method'><a href="handlers.html#.jiffClient.handlers.receive_custom">jiffClient.handlers.receive_custom</a></li><li data-type='method'><a href="handlers.html#.jiffClient.handlers.receive_open">jiffClient.handlers.receive_open</a></li><li data-type='method'><a href="handlers.html#.jiffClient.handlers.receive_share">jiffClient.handlers.receive_share</a></li><li data-type='method'><a href="handlers.html#.jiffClient.handlers.store_public_keys">jiffClient.handlers.store_public_keys</a></li></ul></li><li><a href="helpers.html">helpers</a><ul class='methods'><li data-type='method'><a href="helpers.html#.jiffClient.helpers.array_equals">jiffClient.helpers.array_equals</a></li><li data-type='method'><a href="helpers.html#.jiffClient.helpers.bits_to_number">jiffClient.helpers.bits_to_number</a></li><li data-type='method'><a href="helpers.html#.jiffClient.helpers.bLog">jiffClient.helpers.bLog</a></li><li data-type='method'><a href="helpers.html#.jiffClient.helpers.ceil">jiffClient.helpers.ceil</a></li><li data-type='method'><a href="helpers.html#.jiffClient.helpers.extended_gcd">jiffClient.helpers.extended_gcd</a></li><li data-type='method'><a href="helpers.html#.jiffClient.helpers.floor">jiffClient.helpers.floor</a></li><li data-type='method'><a href="helpers.html#.jiffClient.helpers.get_party_number">jiffClient.helpers.get_party_number</a></li><li data-type='method'><a href="helpers.html#.jiffClient.helpers.is_prime">jiffClient.helpers.is_prime</a></li><li data-type='method'><a href="helpers.html#.jiffClient.helpers.mod">jiffClient.helpers.mod</a></li><li data-type='method'><a href="helpers.html#.jiffClient.helpers.number_to_bits">jiffClient.helpers.number_to_bits</a></li><li data-type='method'><a href="helpers.html#.jiffClient.helpers.pow_mod">jiffClient.helpers.pow_mod</a></li><li data-type='method'><a href="helpers.html#.jiffClient.helpers.random">jiffClient.helpers.random</a></li><li data-type='method'><a href="helpers.html#.jiffClient.helpers.sort_ids">jiffClient.helpers.sort_ids</a></li><li data-type='method'><a href="helpers.html#.jiffClient.helpers.Zp_equals">jiffClient.helpers.Zp_equals</a></li></ul></li><li><a href="hooks.html">hooks</a><ul class='methods'><li data-type='method'><a href="hooks.html#.computeShares">computeShares</a></li><li data-type='method'><a href="hooks.html#.execute_array_hooks">execute_array_hooks</a></li></ul></li><li><a href="protocols.html">protocols</a><ul class='methods'><li data-type='method'><a href="protocols.html#.jiffClient.protocols.generate_beaver_bgw">jiffClient.protocols.generate_beaver_bgw</a></li><li data-type='method'><a href="protocols.html#.jiffClient.protocols.generate_random_and_quotient">jiffClient.protocols.generate_random_and_quotient</a></li><li data-type='method'><a href="protocols.html#.jiffClient.protocols.generate_random_bit_bgw">jiffClient.protocols.generate_random_bit_bgw</a></li><li data-type='method'><a href="protocols.html#.jiffClient.protocols.generate_random_bit_smult">jiffClient.protocols.generate_random_bit_smult</a></li><li data-type='method'><a href="protocols.html#.jiffClient.protocols.generate_random_bits">jiffClient.protocols.generate_random_bits</a></li><li data-type='method'><a href="protocols.html#.jiffClient.protocols.generate_random_number">jiffClient.protocols.generate_random_number</a></li><li data-type='method'><a href="protocols.html#.jiffClient.protocols.generate_zero">jiffClient.protocols.generate_zero</a></li><li data-type='method'><a href="protocols.html#.jiffClient.protocols.rejection_sampling">jiffClient.protocols.rejection_sampling</a></li></ul></li><li><a href="utils.html">utils</a><ul class='methods'><li data-type='method'><a href="utils.html#.jiffClient.utils.bit_combinator">jiffClient.utils.bit_combinator</a></li><li data-type='method'><a href="utils.html#.jiffClient.utils.many_secret_shares">jiffClient.utils.many_secret_shares</a></li><li data-type='method'><a href="utils.html#.jiffClient.utils.resolve_many_secrets">jiffClient.utils.resolve_many_secrets</a></li></ul></li></ul>
</nav>

<div id="main">
    
    <h1 class="page-title">client/api/bits.js</h1>
    

    



    
    <section>
        <article>
            <pre class="prettyprint source linenums"><code>var arithmetic = require('../protocols/bits/arithmetic.js');
var comparison = require('../protocols/bits/comparison.js');
var otherProtocols = require('../protocols/bits/protocols.js');
var sharing = require('../protocols/bits/sharing.js');

/**
 * Contains bits protocols (including rejection sampling and bits operations)
 *
 * &lt;b>Important: bit protocols (including bit_decomposition) are unaware of any extension specific customizations, and will operate as
 * on the given shares as if they are natural numbers in Zp. Make sure to take into consideration any magnification/shift transformations
 * needed to translate correctly between plain representations and extension representations of bits! &lt;/b>
 * @alias bits
 * @namespace
 */

module.exports = function (jiffClient) {
  /**
   * Compute sum of bitwise secret shared number and a constant
   * @method
   * @memberof bits
   * @param {module:jiff-client~JIFFClient#SecretShare[]} bits - the bit wise secret shares
   * @param {number} constant - the constant
   * @param {string} [op_id=&lt;auto-generate-id>] - the base operation id to use when generating unique ids for communication
   *                                              default value should suffice when the code of all parties executes all instructions
   *                                              in the same exact order, otherwise, a unique base name is needed here
   * @returns {module:jiff-client~JIFFClient#SecretShare[]} bitwise sharing of the result. Note that the length here will be max(|bits|, |constant|) + 1
   *                          in case of potential overflow / carry
   */
  jiffClient.protocols.bits.cadd = arithmetic.cadd.bind(null, jiffClient);
  /**
   * Compute [secret bits] - [constant bits]
   * @method
   * @memberof bits
   * @param {number} constant - the constant
   * @param {module:jiff-client~JIFFClient#SecretShare[]} bits - the bit wise secret shares
   * @param {string} [op_id=&lt;auto-generate-id>] - the base operation id to use when generating unique ids for communication.
   *                                              default value should suffice when the code of all parties executes all instructions
   *                                              in the same exact order, otherwise, a unique base name is needed here
   * @returns {module:jiff-client~JIFFClient#SecretShare[]} bitwise sharing of the result. Note that the length of the returned result is |bits|+1, where
   *                          the bit at index 0 is the least significant bit. The bit at index 1 is the most significant bit,
   *                          and the bit at index |bits| is 1 if the result overflows, or 0 otherwise
   */
  jiffClient.protocols.bits.csubl = arithmetic.csubl.bind(null, jiffClient);
  /**
   * Compute [constant bits] - [secret bits]
   * @method
   * @memberof bits
   * @param {number} constant - the constant
   * @param {module:jiff-client~JIFFClient#SecretShare[]} bits - the bit wise secret shares
   * @param {string} [op_id=&lt;auto-generate-id>] - the base operation id to use when generating unique ids for communication.
   *                                              default value should suffice when the code of all parties executes all instructions
   *                                              in the same exact order, otherwise, a unique base name is needed here
   * @returns {module:jiff-client~JIFFClient#SecretShare[]} bitwise sharing of the result. Note that the length of the returned result is |bits|+1, where
   *                          the bit at index 0 is the least significant bit. The bit at index 1 is the most significant bit,
   *                          and the bit at index |bits| is 1 if the result overflows, or 0 otherwise
   */
  jiffClient.protocols.bits.csubr = arithmetic.csubr.bind(null, jiffClient);
  /**
   *
   * Compute [secret bits1] + [secret bits2]
   * @method
   * @memberof bits
   * @param {module:jiff-client~JIFFClient#SecretShare[]} bits1 - the first bitwise shared number: array of secrets with index 0 being least significant bit
   * @param {module:jiff-client~JIFFClient#SecretShare[]} bits2 - the second bitwise shared number (length may be different)
   * @param {string} [op_id=&lt;auto-generate-id>] - the base operation id to use when generating unique ids for communication.
   *                                              default value should suffice when the code of all parties executes all instructions
   *                                              in the same exact order, otherwise, a unique base name is needed here
   * @returns {module:jiff-client~JIFFClient#SecretShare[]} bitwise sharing of the result. Note that the length of the returned result is |bits|+1, where
   *                          the bit at index 0 is the least significant bit
   */
  jiffClient.protocols.bits.sadd = arithmetic.sadd.bind(null, jiffClient);
  /**
   * Compute [secret bits1] - [secret bits2]
   * @method
   * @memberof bits
   * @param {module:jiff-client~JIFFClient#SecretShare[]} bits1 - first bitwise secret shared number: lower indices represent less significant bits
   * @param {module:jiff-client~JIFFClient#SecretShare[]} bits2 - second bitwise secret shared number (length may be different)
   * @param {string} [op_id=&lt;auto-generate-id>] - the base operation id to use when generating unique ids for communication.
   *                                              default value should suffice when the code of all parties executes all instructions
   *                                              in the same exact order, otherwise, a unique base name is needed here
   * @returns {module:jiff-client~JIFFClient#SecretShare[]} bitwise sharing of the result. Note that the length of the returned result is |bits|+1, where
   *                          the bit at index 0 is the least significant bit. The bit at index 1 is the most significant bit,
   *                          and the bit at index |bits| is 1 if the result overflows, or 0 otherwise
   */
  jiffClient.protocols.bits.ssub = arithmetic.ssub.bind(null, jiffClient);
  /**
   * Compute [secret bits] * constant
   * @method
   * @memberof bits
   * @param {module:jiff-client~JIFFClient#SecretShare[]} bits - bitwise shared secret to multiply: lower indices represent less significant bits
   * @param {number} constant - constant to multiply with
   * @param {string} [op_id=&lt;auto-generate-id>] - the base operation id to use when generating unique ids for communication.
   *                                              default value should suffice when the code of all parties executes all instructions
   *                                              in the same exact order, otherwise, a unique base name is needed here
   * @returns {module:jiff-client~JIFFClient#SecretShare[]} bitwise sharing of the result, the length of the result will be bits.length + ceil(log2(constant)), except
   *                          if constant is zero, the result will then be [ zero share ]
   */
  jiffClient.protocols.bits.cmult = arithmetic.cmult.bind(null, jiffClient);
  /**
   * Compute [secret bits1] * [secret bits2]
   * @method
   * @memberof bits
   * @param {module:jiff-client~JIFFClient#SecretShare[]} bits1 - bitwise shared secret to multiply: lower indices represent less significant bits
   * @param {module:jiff-client~JIFFClient#SecretShare[]} bits2 - bitwise shared secret to multiply
   * @param {string} [op_id=&lt;auto-generate-id>] - the base operation id to use when generating unique ids for communication.
   *                                              default value should suffice when the code of all parties executes all instructions
   *                                              in the same exact order, otherwise, a unique base name is needed here
   * @returns {module:jiff-client~JIFFClient#SecretShare[]} bitwise sharing of the result, the length of the result will be bits1.length + bits2.length
   */
  jiffClient.protocols.bits.smult = arithmetic.smult.bind(null, jiffClient);
  /**
   * Computes integer division of [secret bits 1] / [secret bits 2]
   * @method
   * @memberof bits
   * @param {module:jiff-client~JIFFClient#SecretShare[]} bits1 - an array of secret shares of bits, starting from least to most significant bits
   * @param {module:jiff-client~JIFFClient#SecretShare[]} bits2 - the second bitwise shared number
   * @param {string} [op_id=&lt;auto-generate-id>] - the base operation id to use when generating unique ids for multiplications
   *                                              default value should suffice when the code of all parties executes all instructions
   *                                              in the same exact order, otherwise, a unique base name is needed here
   * @returns {{quotient: module:jiff-client~JIFFClient#SecretShare[], remainder: module:jiff-client~JIFFClient#SecretShare[]}} the quotient and remainder bits arrays, note that
   *                                                                the quotient array has the same length as bits1,
   *                                                                and the remainder array has the same length as bits2 or bits1, whichever is smaller.
   *                                                                Note: if bits2 represent 0, the returned result is the maximum
   *                                                                number that fits in the number of bits (all 1), and the remainder
   *                                                                is equal to bits1
   */
  jiffClient.protocols.bits.sdiv = arithmetic.sdiv.bind(null, jiffClient);
  /**
   * Computes integer division of [secret bits] / constant
   * @method
   * @memberof bits
   * @param {module:jiff-client~JIFFClient#SecretShare[]} bits - numerator: an array of secret shares of bits, starting from least to most significant bits
   * @param {number} constant - the denominator number
   * @param {string} [op_id=&lt;auto-generate-id>] - the base operation id to use when generating unique ids for multiplications.
   *                                              default value should suffice when the code of all parties executes all instructions
   *                                              in the same exact order, otherwise, a unique base name is needed here
   * @returns {{quotient: module:jiff-client~JIFFClient#SecretShare[], remainder: module:jiff-client~JIFFClient#SecretShare[]}} the quotient and remainder bits arrays, note that
   *                                                                the quotient array has the same length as bits,
   *                                                                and the remainder array has the same length as
   *                                                                constant or bits, whichever is smaller
   * @throws if constant is 0.
   */
  jiffClient.protocols.bits.cdivl = arithmetic.cdivl.bind(null, jiffClient);
  /**
   * Computes integer division of constant / [secret bits]
   * @method
   * @memberof bits
   * @param {number} constant - the numerator number
   * @param {module:jiff-client~JIFFClient#SecretShare[]} bits - denominator: an array of secret shares of bits, starting from least to most significant bits
   * @param {string} [op_id=&lt;auto-generate-id>] - the base operation id to use when generating unique ids for multiplications.
   *                                              default value should suffice when the code of all parties executes all instructions
   *                                              in the same exact order, otherwise, a unique base name is needed here
   * @returns {{quotient: module:jiff-client~JIFFClient#SecretShare[], remainder: module:jiff-client~JIFFClient#SecretShare[]}} the quotient and remainder bits arrays, note that
   *                                                                the quotient array has the same length as the number of bits in constant,
   *                                                                and the remainder array has the same length as bits or constant, whichever is smaller.
   *                                                                Note: if bits represent 0, the returned result is the maximum
   *                                                                number that fits in its bits (all 1), and the remainder
   *                                                                is equal to constant
   */
  jiffClient.protocols.bits.cdivr = arithmetic.cdivr.bind(null, jiffClient);

  /**
   * Checks whether the given bitwise secret shared number and numeric constant are equal
   * @method
   * @memberof bits
   * @param {module:jiff-client~JIFFClient#SecretShare[]} bits - an array of secret shares of bits, starting from least to most significant bits
   * @param {number} constant - the constant number
   * @param {string} [op_id=&lt;auto-generate-id>] - the base operation id to use when generating unique ids for multiplications.
   *                                              default value should suffice when the code of all parties executes all instructions
   *                                              in the same exact order, otherwise, a unique base name is needed here
   * @returns {SecretShare|boolean} a secret share of 1 if parameters are equal, 0 otherwise. If result is known
   *                                (e.g. constant has a greater non-zero bit than bits' most significant bit), the result is
   *                                returned immediately as a boolean
   */
  jiffClient.protocols.bits.ceq = comparison.ceq.bind(null, jiffClient);
  /**
   * Checks whether the given bitwise secret shared number and numeric constant are not equal
   * @method
   * @memberof bits
   * @param {module:jiff-client~JIFFClient#SecretShare[]} bits - an array of secret shares of bits, starting from least to most significant bits
   * @param {number} constant - the constant number
   * @param {string} [op_id=&lt;auto-generate-id>] - the base operation id to use when generating unique ids for multiplications.
   *                                              default value should suffice when the code of all parties executes all instructions
   *                                              in the same exact order, otherwise, a unique base name is needed here
   * @returns {SecretShare|boolean} a secret share of 1 if parameters are not equal, 0 otherwise. If result is known
   *                                (e.g. constant has a greater non-zero bit than bits' most significant bit), the result is
   *                                returned immediately as a boolean
   */
  jiffClient.protocols.bits.cneq = comparison.cneq.bind(null, jiffClient);
  /**
   * Checks whether given secret shared bits are greater than the given constant
   * @method
   * @memberof bits
   * @param {module:jiff-client~JIFFClient#SecretShare[]} bits - an array of the secret shares of bits, starting from least to most significant bits
   * @param {number} constant - the constant number
   * @param {string} [op_id=&lt;auto-generate-id>] - the base operation id to use when generating unique ids for multiplications
   *                                              default value should suffice when the code of all parties executes all instructions
   *                                              in the same exact order, otherwise, a unique base name is needed here
   * @returns {SecretShare|boolean} a secret share of 1 if bits are greater than constant, 0 otherwise, if result is known
   *                                (e.g. constant has greater non-zero bit than bits' most significant bit), the result is
   *                                returned immediately as a boolean
   */
  jiffClient.protocols.bits.cgt = comparison.cgt.bind(null, jiffClient);
  /**
   * Checks whether given secret shared bits are greater or equal to the given constant
   * @method
   * @memberof bits
   * @param {module:jiff-client~JIFFClient#SecretShare[]} bits - an array of the secret shares of bits, starting from least to most significant bits
   * @param {number} constant - the constant number
   * @param {string} [op_id=&lt;auto-generate-id>] - the base operation id to use when generating unique ids for multiplications.
   *                                              default value should suffice when the code of all parties executes all instructions
   *                                              in the same exact order, otherwise, a unique base name is needed here
   * @returns {SecretShare|boolean} a secret share of 1 if bits are greater or equal to constant, 0 otherwise, if result is known
   *                                (e.g. constant has greater non-zero bit than bits' most significant bit or constant is zero), the result is
   *                                returned immediately as a boolean
   */
  jiffClient.protocols.bits.cgteq = comparison.cgteq.bind(null, jiffClient);
  /**
   * Checks whether given secret shared bits are less than the given constant
   * @method
   * @memberof bits
   * @param {module:jiff-client~JIFFClient#SecretShare[]} bits - an array of the secret shares of bits, starting from least to most significant bits
   * @param {number} constant - the constant number
   * @param {string} [op_id=&lt;auto-generate-id>] - the base operation id to use when generating unique ids for multiplications.
   *                                              default value should suffice when the code of all parties executes all instructions
   *                                              in the same exact order, otherwise, a unique base name is needed here
   * @returns {SecretShare|boolean} a secret share of 1 if bits are less than the constant, 0 otherwise, if result is known
   *                                (e.g. constant has greater non-zero bit than bits' most significant bit), the result is
   *                                returned immediately as a boolean
   */
  jiffClient.protocols.bits.clt = comparison.clt.bind(null, jiffClient);
  /**
   * Checks whether given secret shared bits are less or equal to the given constant
   * @method
   * @memberof bits
   * @param {module:jiff-client~JIFFClient#SecretShare[]} bits - an array of the secret shares of bits, starting from least to most significant bits
   * @param {number} constant - the constant number
   * @param {string} [op_id=&lt;auto-generate-id>] - the base operation id to use when generating unique ids for multiplications.
   *                                              default value should suffice when the code of all parties executes all instructions
   *                                              in the same exact order, otherwise, a unique base name is needed here
   * @returns {SecretShare|boolean} a secret share of 1 if bits are less or equal to constant, 0 otherwise, if result is known
   *                                (e.g. constant has greater non-zero bit than bits' most significant bit), the result is
   *                                returned immediately as a boolean
   */
  jiffClient.protocols.bits.clteq = comparison.clteq.bind(null, jiffClient);
  /**
   * Checks whether the two given bitwise secret shared numbers are equal
   * @method
   * @memberof bits
   * @param {module:jiff-client~JIFFClient#SecretShare[]} bits1 - an array of secret shares of bits, starting from least to most significant bits
   * @param {module:jiff-client~JIFFClient#SecretShare[]} bits2 - the second bitwise shared number
   * @param {string} [op_id=&lt;auto-generate-id>] - the base operation id to use when generating unique ids for multiplications.
   *                                              default value should suffice when the code of all parties executes all instructions
   *                                              in the same exact order, otherwise, a unique base name is needed here
   * @returns {module:jiff-client~JIFFClient#SecretShare} a secret share of 1 if bits are equal, 0 otherwise
   */
  jiffClient.protocols.bits.seq = comparison.seq.bind(null, jiffClient);
  /**
   * Checks whether the two given bitwise secret shared numbers are not equal
   * @method
   * @memberof bits
   * @param {module:jiff-client~JIFFClient#SecretShare[]} bits1 - an array of secret shares of bits, starting from least to most significant bits
   * @param {module:jiff-client~JIFFClient#SecretShare[]} bits2 - the second bitwise shared number
   * @param {string} [op_id=&lt;auto-generate-id>] - the base operation id to use when generating unique ids for multiplications.
   *                                              default value should suffice when the code of all parties executes all instructions
   *                                              in the same exact order, otherwise, a unique base name is needed here
   * @returns {module:jiff-client~JIFFClient#SecretShare} a secret share of 1 if bits are not equal, 0 otherwise
   */
  jiffClient.protocols.bits.sneq = comparison.sneq.bind(null, jiffClient);
  /**
   * Checks whether the first given bitwise secret shared number is greater than the second bitwise secret shared number
   * @method
   * @memberof bits
   * @param {module:jiff-client~JIFFClient#SecretShare[]} bits1 - an array of secret shares of bits, starting from least to most significant bits
   * @param {module:jiff-client~JIFFClient#SecretShare[]} bits2 - the second bitwise shared number
   * @param {string} [op_id=&lt;auto-generate-id>] - the base operation id to use when generating unique ids for multiplications.
   *                                              default value should suffice when the code of all parties executes all instructions
   *                                              in the same exact order, otherwise, a unique base name is needed here
   * @returns {module:jiff-client~JIFFClient#SecretShare} a secret share of 1 if the first number is greater than the second, 0 otherwise
   */
  jiffClient.protocols.bits.sgt = comparison.sgt.bind(null, jiffClient);
  /**
   * Checks whether the first given bitwise secret shared number is greater than or equal to the second bitwise secret shared number
   * @method
   * @memberof bits
   * @param {module:jiff-client~JIFFClient#SecretShare[]} bits1 - an array of secret shares of bits, starting from least to most significant bits
   * @param {module:jiff-client~JIFFClient#SecretShare[]} bits2 - the second bitwise shared number
   * @param {string} [op_id=&lt;auto-generate-id>] - the base operation id to use when generating unique ids for multiplications.
   *                                              default value should suffice when the code of all parties executes all instructions
   *                                              in the same exact order, otherwise, a unique base name is needed here
   * @returns {module:jiff-client~JIFFClient#SecretShare} a secret share of 1 if the first number is greater or equal to the second, 0 otherwise
   */
  jiffClient.protocols.bits.sgteq = comparison.sgteq.bind(null, jiffClient);
  /**
   * Checks whether the first given bitwise secret shared number is less than the second bitwise secret shared number
   * @method
   * @memberof bits
   * @param {module:jiff-client~JIFFClient#SecretShare[]} bits1 - an array of secret shares of bits, starting from least to most significant bits
   * @param {module:jiff-client~JIFFClient#SecretShare[]} bits2 - the second bitwise shared number
   * @param {string} [op_id=&lt;auto-generate-id>] - the base operation id to use when generating unique ids for multiplications.
   *                                              default value should suffice when the code of all parties executes all instructions
   *                                              in the same exact order, otherwise, a unique base name is needed here
   * @returns {module:jiff-client~JIFFClient#SecretShare} a secret share of 1 if the first number is less than the second, 0 otherwise
   */
  jiffClient.protocols.bits.slt = comparison.slt.bind(null, jiffClient);
  /**
   * Checks whether the first given bitwise secret shared number is less or equal to the second bitwise secret shared number
   * @method
   * @memberof bits
   * @param {module:jiff-client~JIFFClient#SecretShare[]} bits1 - an array of secret shares of bits, starting from least to most significant bits
   * @param {module:jiff-client~JIFFClient#SecretShare[]} bits2 - the second bitwise shared number
   * @param {string} [op_id=&lt;auto-generate-id>] - the base operation id to use when generating unique ids for multiplications.
   *                                              default value should suffice when the code of all parties executes all instructions
   *                                              in the same exact order, otherwise, a unique base name is needed here
   * @returns {module:jiff-client~JIFFClient#SecretShare} a secret share of 1 if the first number is less than or equal to the second, 0 otherwise
   */
  jiffClient.protocols.bits.slteq = comparison.slteq.bind(null, jiffClient);

  /**
   * Retrieves preprocessed rejection_sampling bits or performs the rejection sampling on the fly if crypto_provider is enabled
   * @method
   * @memberof bits
   * @param {number} lower_bound - the lower bound, included (can be a bigNumber if using bigNumber extension)
   * @param {number} upper_bound - the upper bound, excluded (can be a bigNumber if using bigNumber extension)
   * @param {number} [threshold=parties.length] - the threshold of the resulting shares after sampling
   * @param {Array} [parties=all_parties] - array of party ids that want to receive (or compute if needed) the sampling shares, by default, this includes all parties
   * @param {number} [Zp=jiff-instance.Zp] - the mod (if null then the default Zp for the instance is used)
   * @param {string} [op_id=auto_gen()] - the operation id which is used to identify this operation.
   *                         This id must be unique, and must be passed by all parties to the same instruction, to
   *                         ensure that corresponding instructions across different parties are matched correctly
   * @returns {SecretShare[]} an array of secret shares, each representing a bit from the sampled value (from least to most significant)
   */
  jiffClient.protocols.bits.rejection_sampling = otherProtocols.rejection_sampling.bind(null, jiffClient);

  /**
   * Creates a secret share of the number represented by the given array of secret shared bits.
   * Requires no communication, only local operations
   * @method
   * @memberof bits
   * @param {module:jiff-client~JIFFClient#SecretShare[]} bits - an array of the secret shares of bits, starting from least to most significant bits.
   * @returns {module:jiff-client~JIFFClient#SecretShare} a secret share of the number represented by bits.
   */
  jiffClient.protocols.bits.bit_composition = otherProtocols.bit_composition;

  /**
   * Share a number as an array of secret bits
   * This takes the same parameters as jiff-instance.share, but returns an array of secret bit shares per sending party.
   * Each bit array starts with the least significant bit at index 0, and most significant bit at index length-1
   * @method
   * @memberof bits
   * @param {number} secret - the number to share (this party's input)
   * @param {number} [bit_length=jiff_instance.Zp] - the number of generated bits, if the secret has less bits, it will be
   *                                                 padded with zeros
   * @param {number} [threshold=receivers_list.length] - threshold of each shared bit
   * @param {Array} [receivers_list=all_parties] - receivers of every bits
   * @param {Array} [senders_list=all_parties] - senders of evey bit
   * @param {number} [Zp=jiff_instance.Zp] - the field of sharing for every bit
   * @param {string|number} [share_id=auto_gen()] - synchronization id
   * @returns {object} a map (of size equal to the number of parties)
   *          where the key is the party id (from 1 to n)
   *          and the value is an array of secret shared bits
   */
  jiffClient.protocols.bits.share = sharing.share_bits.bind(null, jiffClient);
  /**
   * Opens the given array of secret shared bits.
   * This works regardless of whether the represented value fit inside the corresponding field or not
   * @method
   * @memberof bits
   * @param {module:jiff-client~JIFFClient#SecretShare[]} bits - an array of the secret shares of bits, starting from least to most significant bits
   * @param {number[]} parties - parties to open (same as jiff_instance.open)
   * @param {string|number} [op_id=auto_gen()] - same as jiff_instance.open
   * @returns {promise} a promise to the number represented by bits
   */
  jiffClient.protocols.bits.open = sharing.open_bits.bind(null, jiffClient);
  /**
   * Receives an opening of an array of secret bits without owning shares of the underlying value.
   * Similar to jiff.receive_open() but for bits.
   * This works regardless of whether the represented value fit inside the corresponding field or not
   * @method
   * @memberOf jiff-instance.protocols.bits
   * @param {Array} senders - an array with party ids (1 to n) specifying the parties sending the shares
   * @param {Array} [receivers=all_parties] - an array with party ids (1 to n) specifying the parties receiving the result
   * @param {number} [count=ceil(log2(Zp))] - the number of bits being opened
   * @param {number} [threshold=parties.length] - the min number of parties needed to reconstruct the secret, defaults to all the senders
   * @param {number} [Zp=jiff_instance.Zp] - the mod (if null then the default Zp for the instance is used)
   * @param {string|number|object} [op_id=auto_gen()] - unique and consistent synchronization id between all parties
   * @returns {promise} a (JQuery) promise to the open value of the secret
   */
  jiffClient.protocols.bits.receive_open = sharing.receive_open_bits.bind(null, jiffClient);
};</code></pre>
        </article>
    </section>




    
    
</div>

<br class="clear">

<footer>
    Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.3</a> on Thu Jun 11 2020 12:17:15 GMT-0400 (Eastern Daylight Time) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
</footer>

<script>prettyPrint();</script>
<script src="scripts/polyfill.js"></script>
<script src="scripts/linenumber.js"></script>

<script src="scripts/search.js" defer></script>



</body>
</html>
